class Solution {
    public String minWindow(String s, String t) {
        char[] st = t.toCharArray();
        char[] ss = s.toCharArray();
        int[] hash1 = new int[128];
        for(char ch : st) hash1[ch]++;
        int[] hash2 = new int[128];
        int minlen = Integer.MAX_VALUE,m = -1;
        for(int left = 0,right = 0,count = 0;right < s.length();right++) {
            char in = ss[right];
            if(hash2[in]++ < hash1[in]) count++;

            while(count == st.length) {
                if(right - left + 1 < minlen) {
                    minlen = right - left + 1;
                    m = left;
                }
                char out = ss[left++];
                if(hash1[out] == hash2[out]--) count--;
            }

        }
        if(m == -1) return "";
        String ret = s.substring(m,m + minlen);
        return ret;
    }
}